﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
//using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace iri10
{
    public partial class frmLogIn : Form
    {
        public frmLogIn()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void btnIngresar_Click(object sender, EventArgs e)
        {
            if (!NegUsuario.logIn(txtUsuario.Text, txtPassword.Text))
            {
                lblError.Text = "Usuario o password incorrecto";
                txtPassword.Text = "";
            }
            else
            {
                this.Tag = "Cerrado";
                this.Close();
            }
        }

        private void frmLogIn_Load(object sender, EventArgs e)
        {
            lblError.Text = "";
        }

        private void txtUsuario_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                txtPassword.Focus();
                e.SuppressKeyPress = true; ;
            }
        }

        private void txtPassword_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                btnIngresar_Click(null, null);
                e.SuppressKeyPress = true;
            }
        }


        private void frmLogIn_Shown(object sender, EventArgs e)
        {
            //306 - 242

            int oPos = -Height; //Escondido
            Point p = new Point(306, oPos);

            for (int iCont = 0; iCont <= 20; iCont++)
            {
                p.Y = oPos - (oPos - 242) / 20 * iCont;
                Application.DoEvents();
                this.Location = p;
            }

        }

        private void txtUsuario_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnCancelar_Click(object sender, EventArgs e)
        {
            this.Tag = "Cerrado";
            this.Close();
        }

        public void ocultar()
        {
            //306 - 242

            Point p = new Point();
            p.X = 306;
            p.Y = Location.Y;

            for (int iCont = 25; iCont >= 0; iCont--)
            {
                p.Y -= (242 + this.Height) / 25;
                this.Location = p;
                Application.DoEvents();
            }
        }

        private void frmLogIn_FormClosing(object sender, FormClosingEventArgs e)
        {
            ocultar();
        }
    }
}

